function deepEqual(obj1, obj2) {
    const key1 = Object.keys(obj1);
    const key2 = Object.keys(obj2);

    // 如果包含的属性不一样，直接返回false
    if (key1.length != key2.length) return false;

    for (let index = 0; index < key1.length; index++) {
        const val1 = obj1[key1[index]];
        const val2 = obj2[key2[index]];

        const areObject = isObject(val1) && isObject(val2);
        if (areObject && !deepEqual(val1, val2)
            || !areObject && val1 != val2) return false;
    }

    return true;
}

function isObject(obj) {
    return obj != null && typeof obj === 'object';
}

const hero1 = {
    name: 'Batman',
    address: {
        city: 'Gotham',
        age: 19
    }
};
const hero2 = {
    name: 'Batman',
    address: {
        city: 'Gotham',
        age: 19
    }
};

var res = deepEqual(hero1, hero2);
console.log(res);